package com.ruoyi.project.mall.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.mall.domain.MallShopTypeDO;
import com.ruoyi.project.mall.service.MallShopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 商家注册行业类别
 * 
 * @author long
 * @email 499626561@qq.com
 * @date 2020-12-31 11:15:20
 */
 
@Controller
@RequestMapping("/mall/mallShopType")
public class MallShopTypeController extends BaseController {
	@Autowired
	private MallShopTypeService mallShopTypeService;
	
	/*@GetMapping()
	@RequiresPermissions("mall:mallShopType:mallShopType")
	String MallShopType(){
	    return "mall/mallShopType/mallShopType";
	}*/

	/**
	 * 查询行业设置列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:list')")
	@GetMapping("/list")
	public TableDataInfo list(MallShopTypeDO mallShopType)
	{
		startPage();
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(mallShopType);
		stringObjectMap.put("delFlag","0");
		stringObjectMap.put("sort","ca_at");
		stringObjectMap.put("order","desc");
		List<MallShopTypeDO> list = mallShopTypeService.list(stringObjectMap);
		return getDataTable(list);
	}


	/**
	 * 导出行业设置列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:export')")
	@Log(title = "行业设置", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(MallShopTypeDO mallShopType)
	{
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(mallShopType);
		List<MallShopTypeDO> list = mallShopTypeService.list(stringObjectMap);
		ExcelUtil<MallShopTypeDO> util = new ExcelUtil<MallShopTypeDO>(MallShopTypeDO.class);
		return util.exportExcel(list, "mallShopType");
	}

	/**
	 * 获取行业设置详细信息
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") String id)
	{
		return AjaxResult.success(mallShopTypeService.get(id));
	}

	/**
	 * 新增行业设置
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:add')")
	@Log(title = "行业设置", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MallShopTypeDO mallShopType)
	{

		mallShopType.setId(IdUtil.simpleUUID());
		mallShopType.setDelFlag(0);
		mallShopType.setCaAt(new Date());
		return toAjax(mallShopTypeService.save(mallShopType));
	}

	/**
	 * 修改行业设置
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:edit')")
	@Log(title = "行业设置", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MallShopTypeDO mallShopType)
	{
		mallShopType.setUpAt(new Date());
		return toAjax(mallShopTypeService.update(mallShopType));
	}

	/**
	 * 删除行业设置
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('mall:mallShopType:remove')")
	@Log(title = "行业设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable String[] ids)
	{
		if(ids.length>0){
			for (String string : ids) {
				MallShopTypeDO mallShopType = mallShopTypeService.get(string);
				mallShopType.setDelFlag(1);
				mallShopType.setUpAt(new Date());
				mallShopTypeService.update(mallShopType);
			}
		}
		return toAjax(ids.length);
	}
	
	/*@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("mall:mallShopType:mallShopType")
	public PageUtils list(@RequestParam Map<String, Object> params){
	    params.put("delFlag","0");
	    params.put("sort","ca_at");
	    params.put("order","desc");
        //查询列表数据
        Query query = new Query(params);
	    if(params.containsKey("name")&& StringUtils.isNotBlank(params.get("name").toString())){
            List<MallShopTypeDO> mallShopTypeList = mallShopTypeService.likeList(query);
            int total = mallShopTypeService.likeListCount(query);
            PageUtils pageUtils = new PageUtils(mallShopTypeList, total);
            return pageUtils;
		}

		List<MallShopTypeDO> mallShopTypeList = mallShopTypeService.list(query);
		int total = mallShopTypeService.count(query);
		PageUtils pageUtils = new PageUtils(mallShopTypeList, total);
		return pageUtils;
	}*/
	
	/*@GetMapping("/add")
	@RequiresPermissions("mall:mallShopType:add")
	String add(){
	    return "mall/mallShopType/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("mall:mallShopType:edit")
	String edit(@PathVariable("id") String id,Model model){
		MallShopTypeDO mallShopType = mallShopTypeService.get(id);
		model.addAttribute("mallShopType", mallShopType);
	    return "mall/mallShopType/edit";
	}
	
	*//**
	 * 保存
	 *//*
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("mall:mallShopType:add")
	public R save(MallShopTypeDO mallShopType){
	    mallShopType.setId(UuidUtil.get32UUID());
	    mallShopType.setDelFlag(0);
	    mallShopType.setCaAt(new Date());
		if(mallShopTypeService.save(mallShopType)>0){
			return R.ok();
		}
		return R.error();
	}
	*//**
	 * 修改
	 *//*
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("mall:mallShopType:edit")
	public R update( MallShopTypeDO mallShopType){
		mallShopType.setUpAt(new Date());
		mallShopTypeService.update(mallShopType);
		return R.ok();
	}
	
	*//**
	 * 删除
	 *//*
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("mall:mallShopType:remove")
	public R remove( String id){
		MallShopTypeDO mallShopType = mallShopTypeService.get(id);
		mallShopType.setDelFlag(1);
		mallShopType.setUpAt(new Date());
		if(mallShopTypeService.update(mallShopType)>0){
		return R.ok();
		}
		return R.error();
	}
	
	*//**
	 * 删除
	 *//*
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("mall:mallShopType:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
	   if(ids.length>0){
			for (String string : ids) {
				MallShopTypeDO mallShopType = mallShopTypeService.get(string);
				mallShopType.setDelFlag(1);
				mallShopType.setUpAt(new Date());
				mallShopTypeService.update(mallShopType);
			}
		}
	
		return R.ok();
	}*/
	
}
